package background

import (
	"clouds.lgb24kcs.cn/controllers/background/request"
	"clouds.lgb24kcs.cn/errorx"
	"clouds.lgb24kcs.cn/global"
	"clouds.lgb24kcs.cn/services/background"
	"clouds.lgb24kcs.cn/utils"
	"github.com/gin-gonic/gin"
)

// @Summary  轮播图添加接口
// @Success 200 {string} string json{"code","message"}
// @Param data body request.CreateCarouselReq{} true "添加请求参数"
// @Router  /admin/v1/carousel/create_share  [PUT]
// @version 1.0
func Create(c *gin.Context) {
	req := request.CreateCarouselReq{}

	if err := c.ShouldBindQuery(&req); err != nil {
		global.APP.Log.Error(err.Error())
		utils.Fail(c, errorx.VerifyError, err.Error())
	} else {
		userId := utils.CtxUserId(c)
		background.CarouselApi.Create(c, req, userId)
	}
}

// @Summary 加载所有轮播图数据
// @Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
// @Router  /admin/v1/carousel/list  [get]
// @version 1.0
func List(c *gin.Context) {
	userId := utils.CtxUserId(c)
	background.CarouselListsApi.Lists(c, userId)
}

// @Summary 删除指定轮播图数据
// @Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
// @Param ID query int true "轮播图ID"
// @Router  /admin/v1/carousel/delete  [DELETE]
// @version 1.0
func Delete(c *gin.Context) {
	/*通过轮播图ID删除*/
	req := request.DeleteCarouselReq{}
	if err := c.ShouldBind(&req); err != nil {
		utils.Fail(c, errorx.VerifyError, err.Error())
	} else {
		userId := utils.CtxUserId(c)
		background.DeleteCarouselApi.Delete(c, req, userId)
	}

}

// @Summary 更新指定轮播图数据
// @Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
// @Param ID query int true "轮播图ID"
// @Router  /admin/v1/carousel/update  [PUT]
// @version 1.0
func Update(c *gin.Context) {
	req := request.UpdateCarouselReq{}
	if err := c.ShouldBind(&req); err != nil {
		utils.Fail(c, errorx.VerifyError, err.Error())
	} else {
		userId := utils.CtxUserId(c)
		background.CarouselUpdateApi.Update(c, req, userId)
	}
}
